package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constants;
import com.bjpowernode.mapper.TClueRemarkMapper;
import com.bjpowernode.model.TActivityRemark;
import com.bjpowernode.model.TClueRemark;
import com.bjpowernode.query.ClueRemarkQuery;
import com.bjpowernode.service.ClueRemarkService;
import com.bjpowernode.util.JWTUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {
    @Resource
    TClueRemarkMapper tClueRemarkMapper;
    @Override
    public int saveClueRemark(ClueRemarkQuery clueRemarkQuery) {
        TClueRemark tClueRemark = new TClueRemark();

        BeanUtils.copyProperties(clueRemarkQuery, tClueRemark);

        tClueRemark.setCreateTime(new Date());//创建时间

        //设置一下创建人
        Integer loginUserId = JWTUtil.parseUserFromJWT(clueRemarkQuery.getJwt()).getId();
        tClueRemark.setCreateBy(loginUserId);

        return tClueRemarkMapper.insertSelective(tClueRemark);
    }

    @Override
    public PageInfo<TClueRemark> getClueRemarkByPage(Integer current, Integer clueId) {
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        //2.查询
        List<TClueRemark> list = tClueRemarkMapper.selectClueRemarkPage(clueId);
        //3.封装分页数据到PageInfo
        PageInfo<TClueRemark> info = new PageInfo<>(list);
        return info;
    }
}
